# !/usr/bin/env python
# -*-coding:utf-8 -*-

"""
# File       : process_param_view.py
# Time       ：2023/12/24 22:09
# Author     ：Y-aong
# version    ：python 3.10
# Description：修改流程参数
"""
import json

from flask import request

from apis.flow import flow_ns
from apis.orderlines.models import Process
from public.api_utils.api_decorator import handle_api_error
from public.base_model import db
from public.base_response import generate_response
from public.base_view import AbstractView


class ProcessParamView(AbstractView):
    url = '/process_param'

    def __init__(self, *args, **kwargs):
        super(ProcessParamView, self).__init__(*args, **kwargs)
        self.form_data = request.json
        self.process_id = self.form_data.pop('process_id')

    @handle_api_error()
    @flow_ns.doc(description='修改流程参数')
    def put(self):
        """修改流程参数"""
        with db.auto_commit():
            db.session.query(Process).filter(
                Process.process_id == self.process_id).update({'process_params': json.dumps(self.form_data)})
        return generate_response(message='流程参数修改成功')
